<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../../plugins/layui/css/layui.css" media="all">
</head>

<body>

  <table class="layui-hide" id="test" lay-filter="test"></table>
  <script type="text/html" id="toolbarDemo">
  </script>

  <script type="text/html" id="barDemo">
  <!-- <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a> -->
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" style="width:50px">就诊</a>
  </script>


  <script src="../../plugins/layui/layui.all.js" charset="utf-8"></script>
  <script src="../../plugins/jquery/jquery.min.js"></script>
  <script>
      var url = location.search;

      var obj = {};
      var reg = /\?/;
      if (url.match(reg)) {
          //判断传入参数，以问号截取，问号后是参数
          var chars = url.split('?')[1];

          //再截&号
          var arr = chars.split('&');

          //获得截取后的数组为键值对字符串
          for (var i = 0; i < arr.length; i++) {

              //保守一点确定看是否为 name=value形式
              var num = arr[i].indexOf("=");

              if (num > 0) {
                  //拼接字符串
                  var name = arr[i].substring(0, num);
                  var value = arr[i].substr(num + 1);

                  //拼接对象，并转码
                  obj[decodeURIComponent(name)] = decodeURIComponent(value);
              }
          }
      }

//      $.ajax({
//          url:"/treatment/view?docId="+obj.doctorId,
//          data:{docId:obj.doctorId},
//          async:true,
//          type:"GET"
//      })

    //window.location="/treatment/view?docId="+obj.doctorId;

  </script>
  <script>
      layui.use('laydate', function(){
          var laydate = layui.laydate;

          laydate.render({
              elem: '#test1'
              ,value:new Date()
              ,done: function(value, date){//控件选择完毕后的回调---点击日期、清空、现在、确定均会触发。
                  var str = value;
                  str.replace('-','')
                  console.log(str);
                   //得到日期生成的值，如：2017-08-18
                  console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
              }
          });

      });

    layui.use('table', function () {
      var table = layui.table;

      table.render({

        elem: '#test'
        ,url:"/treatment/patientPageHelper?docId="+obj.doctorId
        , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
        , defaultToolbar: ['filter', 'exports', 'print', {
          title: '提示'
          , layEvent: 'LAYTABLE_TIPS'
          , icon: 'layui-icon-tips'
        }]
        , title: '用户数据表'
        , cols: [[
          {  fixed: 'left',width:40 }
          , { type: 'numbers', title: '序号' }
          , { field: 'patientName', title: '姓名', width: 80 }
          , { field: 'patientTel', title: '联系方式', width: 120, }
          , { field: 'personCard', title: '身份证号', width: 200, }
          , { field: 'patientAge', title: '年龄', width: 80 }
          , { field: 'patientSex', title: '性别', width: 80 }
          , { field: 'createTime', title: '预约时间', width: 200 }
          , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 80 }
        ]]
        , page: true
      });

      //头工具栏事件
      table.on('toolbar(test)', function (obj) {
        switch (obj.event) {
          //自定义头工具栏右侧图标 - 提示
          case 'LAYTABLE_TIPS':
            layer.alert('这是工具栏右侧自定义的一个图标按钮');
            break;
        };
      });

      //监听行工具事件
      table.on('tool(test)', function (obj) {
        var datas = obj.data;//获取行元素json

        if (obj.event === 'del') {

          layer.open({
            type: 2,
            area: ['400px', '500px'], //宽高

            content: ["medicalrecord.html" + "?patientName=" + datas.patientName + "&patientAge=" + datas.patientAge + "&patientSex=" + datas.patientSex +"&personCard="+ datas.personCard +"&docName="+datas.docName +"&sdeptName="+datas.sdeptName+"&doctorId="+datas.doctorId+"&patientId="+datas.id,"no"],  //调到新增页面

              end:function () {
                  layer.confirm('诊断完成确定是否移除信息',function () {
                          $.ajax({
                          url:"http://localhost:8888/treatment/update",
                          data:{id:datas.id},
                          async:true,
                          type:"POST",
                          success:function(result) {
                              if(result.message == "删除成功"){
                                  layer.msg(result.message)
                                  window.location.reload()
                              }
                          }
                      })

                  })

              }

          });
          // layer.confirm('真的删除行么', function (index) {

          //   obj.del();
          //   layer.close(index);
          // });
        }
      });
    });
  </script>

<script>
    var websocket;

    // 首先判断是否 支持 WebSocket
    if('WebSocket' in window) {

        websocket = new WebSocket("ws://localhost:8888/treatment/wsMy?jspCode=AA");
    } else if('MozWebSocket' in window) {
        websocket = new MozWebSocket("ws://localhost:8888/treatment/wsMy?jspCode=AA");
    } else {
        websocket = new SockJS("ws://localhost:8888/treatment/wsMy?jspCode=AA");
    }

    // 打开连接时
    websocket.onopen = function(event) {
        console.log(" websocket.onopen  ");
    };

    // 收到消息时
    websocket.onmessage = function(event) {
        console.log("收到一条消息"+event.data);
        //alert(event.data);
        layer.confirm(event.data)
    };

    websocket.onerror = function(event) {
        console.log("  websocket.onerror  ");
    };

    websocket.onclose = function(event) {
        console.log("  websocket.onclose  ");
    };
</script>
</body>

</html>